package com.fc.v2.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 通用配置
 * 
 * @author cs
 */
@Configuration
public class ResourcesConfig implements WebMvcConfigurer
{



    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry)
    {
        /* 本地文件上传路径 */
        registry.addResourceHandler("/upload" + "/**").addResourceLocations("file:" + V2Config.getProfile() + "/");

    }


    
//
//    /**
//     * 	这个Filter 解决页面跨域访问问题
//     */
//    @Bean
//    public FilterRegistrationBean omsFilter() {
//        FilterRegistrationBean registration = new FilterRegistrationBean();
//        registration.setFilter(new ServiceFilter());
//        registration.addUrlPatterns("/*");
//        registration.setName("OmsFilter");
//        registration.setAsyncSupported(true);
//        registration.setOrder(1);
//        return registration;
//    }


    
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
    
}